const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const indexHtml = path.join(__dirname, "src", "index.html");
module.exports = {
  entry: { app: "./src/index.js" },
  output: {
    filename: '[name].[hash].js',
    chunkFilename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'file-loader',
          'extract-loader',
          // 'style-loader',
          'css-loader'
        ]
      },
      {
        test: /\.(png|svg|jpg|gif)$/,
        use: ['file-loader']
      },
      // {
      //   test: /\.js$/,
      //   use: [
      //     'file-loader'
      //   ]
      // },
      {
        test: indexHtml,
        use: [
          // {
          //   loader: "file-loader",
          //   options: {
          //     name: "[name]-dist.[ext]",
          //   },
          // },
          // {
          //   loader: "extract-loader",
          // },
          {
            loader: "html-loader",
            options: {
              attrs: ["img:src", "link:href"],
              interpolate: true,
            },
          },
        ],
      },
      {
        test: /\.test$/,
        use: [{
          loader: path.resolve('./testLoader.js'),
          options: {
            foo: 'bar',
            hello: 'world',
            yes: 'no'
          }
        }]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(['dist']),
    new HtmlWebpackPlugin({
      title: '代码分离2',
      template: "./src/index.html",
      filename: "shouye.html"
    })
  ],
};
